import java.util.*;

public class testDemo2 {
    static int[] a;
    static int[] prefix;
    static int getSum(int l,int r) {
        return prefix[r] - prefix[l-1];
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t-- > 0) {
            int n = in.nextInt(),q = in.nextInt();
            a = new int[n + 1];
            prefix = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                a[i] = in.nextInt();
                prefix[i] = prefix[i - 1] + a[i];
            }
            while(q-- > 0) {
                int l = in.nextInt(), r = in.nextInt();
                System.out.println(getSum(l, r));
            }
        }
    }
}
